import './assets/main.css'

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import { createPersistedState } from 'pinia-plugin-persistedstate'

const pinia = createPinia()

pinia.use(createPersistedState({
  storage: sessionStorage,
}))

import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

import axios from 'axios'
//读Api接口
const api1=axios.create({
  baseURL:'http://localhost:5237',
  timeout:10000
})
//写Api接口
const api2=axios.create({
  baseURL:'http://localhost:5127',
  timeout:10000
})
// 添加JWT token信息
//api1.defaults.headers.common["Authorization"] = "Bearer " + window.localStorage.getItem("token");
//api2.defaults.headers.common["Authorization"] = "Bearer " + window.localStorage.getItem("token");
//请求拦截器 客服端每次请求时，自动带上token
api1.interceptors.request.use((config)=>{
  const token=window.localStorage.getItem("token");
  if(token)
  {
    config.headers["Authorization"]=`Bearer ${token}`;
  }
  return config;
},
(error)=>{
  return Promise.reject(error);
}
)

export {api1,api2}


const app = createApp(App)

app.use(createPinia())
app.use(router)
app.use(ElementPlus)
app.use(ElementPlus, {
  locale: zhCn,
})
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
app.use(pinia)

app.mount('#app')
